//
//  MapViewController.m
//  OurTourism
//
//  Created by dllo on 15/11/30.
//  Copyright © 2015年 Devil_Coming. All rights reserved.
//

#import "MapViewController.h"
#import "myAnnotation.h"
#import "Header.h"

@interface MapViewController () <MKMapViewDelegate>
@property (nonatomic,strong) MKMapView * myMapView;
@end

@implementation MapViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    NSString *str = [NSString stringWithFormat:@"%@ %@ %@", self.modelWayPoints.country, self.modelWayPoints.province, self.modelWayPoints.city];
    self.title = str;
    NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:0.36 green:0.73 blue:0.78 alpha:1],NSForegroundColorAttributeName, nil];
    [self.navigationController.navigationBar setTitleTextAttributes:attributes];
    
    //self.map.showsUserLocation = YES;
    self.map = [[MKMapView alloc]initWithFrame:self.view.bounds];
   // 类型
    
    self.map.mapType = MKMapTypeStandard;
    
    
    
    
    [self.view addSubview:self.map];
    CLLocationCoordinate2D coords = CLLocationCoordinate2DMake(self.locationModel.latitude.doubleValue,self.locationModel.longitude.doubleValue);
   // NSLog(@"%f  %f",self.locationModel.latitude.doubleValue,self.locationModel.longitude.doubleValue);
    float zoomLevel = 0.005;
    MKCoordinateRegion region = MKCoordinateRegionMake(coords, MKCoordinateSpanMake(zoomLevel, zoomLevel));
    
    [self.map setRegion:[_map regionThatFits:region] animated:YES];
    
  
    
    
//    
//    //图
//    self.myMapView = [[MKMapView alloc] initWithFrame:self.map.frame];
//    //   self.myMapView.mapType = MKMapTypeHybrid;
//    // self.myMapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
//      self.myMapView.delegate = self;
//    //   self.myMapView.showsUserLocation = YES;
//    self.myMapView.backgroundColor = [UIColor redColor];
//    [_map addSubview:self.myMapView];
    
    
    
    // 初始化MyAnnotation对象并指定该对象地理位置
    myAnnotation *annotation = [[myAnnotation alloc]initWithCoordinate:coords];
    
    annotation.title = [NSString stringWithFormat:@"%@ %@ %@",self.modelWayPoints.country, self.modelWayPoints.province, self.modelWayPoints.city];           //设置标题
    //annotation.subTitle = @"zhe shi na li";      //子标题
    

    
    
    [_map addAnnotation:annotation];
    
 
   
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(20, 20, 40, 40);
    
    [btn setImage:[UIImage imageNamed:@"iconfont-iconfonticonfontjiantouzuo11@2x"] forState:0];
    [btn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    
}

- (void)back
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
